package com.ruoyi.system.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;

/**
 * @author zhm
 * @description MyMetaObjectHandler
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("开始插入填充...");
        this.strictInsertFill(metaObject, "delFlag", String.class, "0");
        this.strictInsertFill(metaObject, "userId", String.class, SecurityUtils.getUserId().toString());
        this.strictInsertFill(metaObject, "createBy", String.class, SecurityUtils.getUserId().toString());
        this.strictInsertFill(metaObject, "createTime", Date.class, DateUtils.getNowDate());
        this.strictInsertFill(metaObject, "updateBy", String.class, SecurityUtils.getUserId().toString());
        this.strictInsertFill(metaObject, "updateTime", Date.class, DateUtils.getNowDate());

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("开始更新填充...");
        this.strictInsertFill(metaObject, "updateBy", String.class, SecurityUtils.getUserId().toString());
        this.strictInsertFill(metaObject, "updateTime", Date.class, DateUtils.getNowDate());
    }
}